package com.xqy.fallback;

import com.xqy.pojo.User;
import com.xqy.service.FeignClientUserService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
@Component
public class  UserServiceFallBack implements FallbackFactory<FeignClientUserService> {

    public FeignClientUserService create(Throwable throwable) {
        return new FeignClientUserService() {
            public List<User> queryList() {
                System.out.println("port:8001.List.fallBack");
                User user = new User();
                user.setUserName("不存在此用户");
                List<User> list = new ArrayList<User>();
                list.add(user);
                return list;
            }

            public User getUser(Integer userId) {
                User user = new User();
                user.setUserName("不存在此用户");
                return user;
            }

            public String getTest() {
                return "hystrix 服务降级";
            }
        };
    }
}
